<!DOCTYPE html>
<html>
<head>
	<title>qipao</title>
	<script type="text/javascript" src="./assets/js/jquery-3.1.1.min.js"></script>
	<style type="text/css">
		.random{
			width: 50px;
			height: 50px;
			background: red;
			border-radius: 50%;
			position: absolute;
			top: 0px;
			left: 0px;
			background-color: #f00;
			transition: all 500ms;
		}
	</style>
</head>
<body>

<div class="random"></div>

<script type="text/javascript">
$(function () {
	function moveDiv() {
	    var $span = $(".random");

	    $span.fadeOut(1000, function() {
	        var maxLeft = $(window).width() - $span.width();
	        var maxTop = $(window).height() - $span.height();
	        var leftPos = Math.floor(Math.random() * (maxLeft + 1))
	        var topPos = Math.floor(Math.random() * (maxTop + 1))

	        $span.css({ left: leftPos, top: topPos }).fadeIn(1000);
	    });
	};

	moveDiv();
	setInterval(moveDiv, 5000);
})
</script>
</body>
</html>